import axios from 'axios'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css' 
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'

const request = axios.create({
  baseURL: import.meta.env.VITE_APP_BASE_API,
  timeout: import.meta.env.VITE_APP_TIMEOUT || 20000,
  withCredentials: true
})
NProgress.configure({ showSpinner: false }) 

request.interceptors.request.use(
  async (config) => {
    NProgress.start()
    //自行实现发送请求前操作 
    return config
  },
  (error) => {
    console.error(error)
    Promise.reject(error)
  }
)

request.interceptors.response.use(
  async (res) => {
      //自行实现响应后操作
      return Promise.resolve(res)
  },
  (error) => {
    return Promise.reject(error)
  }
)
export default request
